home *** CD-ROM | disk | FTP | other *** search
- #include "SystemSoft.h"
- /* NameRegistryDisplayMain.c */
- /*
- * NameRegistryDisplayMain.c
- * Copyright © 1993-95 Apple Computer Inc. All rights reserved.
- * Edit History
- * 1.0a3 (94.12.23) Release for A5 DDK
- * 1.0a4 (94.12.30) Format "reg" property.
- * 1.0a5 (95.01.19) Fix bug: "save doesn't write anything" Correctly
- * dispose of the primary and secondary lists.
- * 1.0b1 (95.03.23) Fix bug: it is possible to have two independent registry
- * entries with the same name. Fix the sort algorithm so
- * they aren't smooshed together.
- */
- #define EXTERN /* Allocate variables */
-
- #include "DisplayNameRegistry.h"
-
- #include "AERegistry.h"
-
- Boolean gSaveAllElements = FALSE;
-
- /*
- * These enum's define items in the various menus.
- */
- enum AppleMenu {
- kAppleAbout = 1
- };
- enum { /* File Menu */
- kFileSaveAs = 1,
- kFileUnused1,
- kFilePageSetup,
- kFilePrint,
- kFileUnused2,
- kFileQuit
- };
- enum EditMenu {
- kEditUndo = 1,
- kEditUnused,
- kEditCut,
- kEditCopy,
- kEditPaste,
- kEditClear
- };
- enum OptionMenu {
- kOptionSortByName = 1,
- kOptionSortByProperty,
- kOptionUnused1,
- kOptionRefreshDisplay,
- kOptionSetFontInfo
- };
-
- Boolean gInForeground;
- long gSleepTime;
-
- // Local function prototypes.
-
- void main(void);
- void ProcessThisEvent( const EventRecord * eventRecordPtr, long * sleepTimePtr);
- void ApplicationEventLoop(void);
- void DoMouseEvent(const EventRecord * eventRecordPtr);
- void DoCommand(WindowPtr activeWindow, long menuChoice);
- void AdjustMenus(void);
- void InitMacintosh(void);
- void InitApplication(void);
- void AdjustEditMenu(Boolean isDeskAcc);
- static Boolean IsOurWindow(WindowPtr theWindow);
- void DoPageSetup(void);
- void DoAbout(void);
- pascal OSErr MyAEOpenAppHandlerFunc(long refCon);
- pascal OSErr MyAEQuitAppHandlerFunc(long refCon);
- pascal void MyAEUnknownHandlerMsgFunc(ConstStr255Param messageText);
- pascal Boolean MyAEIdleProc(const EventRecord *theEventPtr, long *sleepTime, RgnHandle *mouseRgn);
-
- RoutineDescriptor gAEIdleUPP =
- BUILD_ROUTINE_DESCRIPTOR(uppAEIdleProcInfo, MyAEIdleProc);
-
- #ifdef SYSF
- //--------------------------------------------------------------------------------
- // implement the snapshot AppleEvent
- pascal OSErr MyAESnapshotHandlerFunc(AppleEvent *theEvent, AppleEvent *reply, long refCon);
- pascal OSErr MyAESnapshotHandlerFunc(AppleEvent *theEvent, AppleEvent */*reply*/, long /*refCon*/)
- {
- OSStatus err;
- DescType typeCode;
- char outFileName[100];
- Size actualSize;
-
- // see if there is an output filename
- err = AEGetParamPtr(theEvent, keyDirectObject, typeChar, &typeCode, outFileName, sizeof(outFileName), &actualSize);
- if (err == noErr)
- outFileName[actualSize] = 0;
- else
- outFileName[0] = 0;
-
- SnapshotToDisk(true, false, outFileName);
- return (noErr);
- }
-
- //--------------------------------------------------------------------------------
- // implement the rescan AppleEvent
- //pascal OSErr MyAERescanHandlerFunc(AppleEvent *theEvent, AppleEvent *reply, long refCon);
- //pascal OSErr MyAERescanHandlerFunc(AppleEvent *theEvent, AppleEvent */*reply*/, long /*refCon*/)
- //{
- // OSStatus err;
- // DescType typeCode;
- // char outFileName[100];
- // Size actualSize;
- //
- // // see if there is an output filename
- // err = AEGetParamPtr(theEvent, keyDirectObject, typeChar, &typeCode, outFileName, sizeof(outFileName), &actualSize);
- // if (err == noErr)
- // outFileName[actualSize] = 0;
- // else
- // outFileName[0] = 0;
- //
- // if (gCurrentBrowserPtr != nil)
- // {
- // DoRefreshDisplay(gCurrentBrowserPtr);
- // SnapshotToDisk(true, false, outFileName);
- // return (noErr);
- // }
- // return (noErr);
- //}
-
-
- //--------------------------------------------------------------------------------
- // implement the rescan AppleEvent
- pascal OSErr MyAENoSocketsHandlerFunc(AppleEvent *theEvent, AppleEvent *reply, long refCon);
- pascal OSErr MyAENoSocketsHandlerFunc(AppleEvent *theEvent, AppleEvent */*reply*/, long /*refCon*/)
- {
- OSStatus err;
- DescType typeCode;
- char outFileName[100];
- Size actualSize;
-
- // see if there is an output filename
- err = AEGetParamPtr(theEvent, keyDirectObject, typeChar, &typeCode, outFileName, sizeof(outFileName), &actualSize);
- if (err == noErr)
- outFileName[actualSize] = 0;
- else
- outFileName[0] = 0;
-
- SnapshotToDisk(true, true, outFileName);
- return (noErr);
- }
-
- #include <PCCard.h>
-
- Boolean gNeedRefresh = false;
-
- //--------------------------------------------------------------------------
- // Client callback for the sockets
- OSStatus CardStatusEventHandler(PCCardEvent theEvent, PCCardSocket socket, UInt32 device, UInt32 info,
- UInt32 MTDRequest, UInt32 *buffer, UInt32 misc, UInt32 status, void *clientParam);
- OSStatus CardStatusEventHandler(PCCardEvent /*theEvent*/, PCCardSocket /*socket*/, UInt32 /*device*/,
- UInt32 /*info*/, UInt32 /*MTDRequest*/, UInt32 * /*buffer*/, UInt32 /*misc*/,
- UInt32 /*status*/, void * /*clientParam*/)
- {
- #ifdef MEMORY_HOG
- // doing this was causing a bomb - using too much stack for the init
- if (gCurrentBrowserPtr != nil)
- DoRefreshDisplay(gCurrentBrowserPtr);
- #else
- // this is a much more friendly callback
- gNeedRefresh = true;
- #endif
- return noErr;
- }
-
- PCCardClientID gMyClientID = -1;
-
- //--------------------------------------------------------------------------
- void RegisterWithCardServices(void);
- void RegisterWithCardServices(void)
- {
- RegEntryRef wildCard;
- UInt32 theClientParam = 0;
- OSStatus err;
-
-
- err = RegistryEntryIDInit(&wildCard);
-
- err = PCCardRegisterClient(&wildCard, kPCCardInsertionMessage | kPCCardRemovalMessage,
- CardStatusEventHandler, (void *) theClientParam, &gMyClientID);
-
- }
-
- //--------------------------------------------------------------------------
- void DeRegisterWithCardServices(void);
- void DeRegisterWithCardServices(void)
- {
- if (gMyClientID != -1)
- PCCardDeRegisterClient(gMyClientID);
- }
-
-
- #endif
-
- //--------------------------------------------------------------------------------
- // The application main program. This is a limited program for the twist-down
- // sample; it is not intended as a model for a complete Macintosh program.
- void main()
- {
- OSErr status;
-
- InitMacintosh();
- InitApplication();
- status = InitializeAppleEvents(
- MyAEOpenAppHandlerFunc,
- NULL, /* No open doc handler */
- NULL, /* No print doc handler */
- MyAEQuitAppHandlerFunc,
- NULL, /* No DoScript callback */
- MyAEUnknownHandlerMsgFunc,
- 0 /* No refCon */
- );
- if (status != noErr) {
- if (status == gestaltUndefSelectorErr) /* Huh? no AppleEvents? */
- status = MakeNameRegistryBrowserWindow();
- if (status == noErr)
- FatalError(status, "\pCan't initialize AppleEvents");
- }
-
- #ifdef SYSF
- status = AEInstallEventHandler(kAEMiscStandards, kDevRegSnapshot,
- NewAEEventHandlerProc(MyAESnapshotHandlerFunc), 0, FALSE);
- // status = AEInstallEventHandler(kAEMiscStandards, kDevRegRescan,
- // NewAEEventHandlerProc(MyAERescanHandlerFunc), 0, FALSE);
- status = AEInstallEventHandler(kAEMiscStandards, kDevRegNoSockets,
- NewAEEventHandlerProc(MyAENoSocketsHandlerFunc), 0, FALSE);
- RegisterWithCardServices();
- #endif
-
- gInForeground = TRUE;
- gSleepTime = 0;
- InitCursor();
- while (gQuitNow == FALSE) {
- if (gUpdateMenusNeeded)
- AdjustMenus();
- #ifdef SYSF
- if (gNeedRefresh) // if we got a CS notification, rescan the directory
- {
- if (gCurrentBrowserPtr != nil)
- DoRefreshDisplay(gCurrentBrowserPtr);
- gNeedRefresh = false;
- }
- #endif
- WaitNextEvent(everyEvent, &gEventRecord, gSleepTime, NULL);
- gAECoreGlobals.currentEventIsAppleEvent = FALSE;
- ProcessThisEvent(&gEventRecord, &gSleepTime);
- }
- #ifdef SYSF
- DeRegisterWithCardServices();
- #endif
- }
-
- //--------------------------------------------------------------------------------
- pascal OSErr MyAEOpenAppHandlerFunc(long refCon)
- {
- OSErr status;
-
- UNUSED(refCon);
- status = MakeNameRegistryBrowserWindow();
- gUpdateMenusNeeded = TRUE;
- return (status);
- }
-
-
- //--------------------------------------------------------------------------------
- pascal OSErr MyAEQuitAppHandlerFunc(long refCon)
- {
- UNUSED(refCon);
- gQuitNow = TRUE;
- return (noErr);
- }
-
-
- //--------------------------------------------------------------------------------
- pascal void
- MyAEUnknownHandlerMsgFunc(ConstStr255Param messageText)
- {
- NonFatalError(errAEHandlerNotFound, messageText);
- }
-
- //--------------------------------------------------------------------------------
- void ProcessThisEvent(const EventRecord * eventRecordPtr, long * sleepTimePtr)
- {
- OSErr status;
- long menuChoice;
- register WindowPtr theWindow;
- GrafPtr savePort;
- Boolean isActivating;
- #define EVENT (*eventRecordPtr)
-
- theWindow = FrontWindow();
- switch (EVENT.what)
- {
- case nullEvent:
- break;
-
- case keyDown:
- case autoKey:
- if ((EVENT.message & charCodeMask) == '.' && (EVENT.modifiers & cmdKey) != 0)
- {
- FlushEvents(keyDown | autoKey, 0);
- gQuitNow = TRUE;
- }
- else if ((EVENT.modifiers & cmdKey) != 0)
- {
- if (EVENT.what == keyDown)
- {
- menuChoice = MenuKey(EVENT.message & charCodeMask);
- if (HiWord(menuChoice) != 0 && IsOurWindow(theWindow))
- DoCommand(theWindow, menuChoice);
- else if (IsOurWindow(theWindow))
- DoWindowKeyDown((BrowserPtr) theWindow);
- else
- SysBeep(10);
- }
- }
- else if (IsOurWindow(theWindow))
- DoWindowKeyDown((BrowserPtr) theWindow);
- else
- SysBeep(10);
- break;
-
- case mouseDown:
- DoMouseEvent(eventRecordPtr);
- break;
-
- case updateEvt:
- theWindow = (WindowPtr) EVENT.message;
- GetPort(&savePort);
- SetPort(theWindow);
- BeginUpdate(theWindow);
- EraseRect(&theWindow->portRect);
- DrawGrowIcon(theWindow);
- DrawControls(theWindow);
- if (IsOurWindow(theWindow))
- UpdateBrowserWindow((BrowserPtr) theWindow, theWindow->visRgn);
- EndUpdate(theWindow);
- SetPort(savePort);
- break;
-
- case activateEvt:
- theWindow = (WindowPtr) EVENT.message;
- isActivating = ((EVENT.modifiers & activeFlag) != 0);
- goto activateEvent;
- break;
-
- case kHighLevelEvent:
- status = AEProcessAppleEvent(&EVENT);
- switch (status)
- {
- case userCanceledErr:
- case errAEEventNotHandled:
- case noErr:
- break;
- default:
- NonFatalError(status, "\pAppleEvent handler error");
- break;
- }
- break;
-
- #ifdef SYSF
- case diskEvt:
- if (HiWord(EVENT.message) != noErr)
- {
- Point p = {120,120};
-
- DILoad();
- DIBadMount(p, EVENT.message);
- DIUnload();
- }
- #endif
-
- case osEvt:
- switch (((unsigned long) EVENT.message) >> 24)
- {
- case mouseMovedMessage:
- break;
- case suspendResumeMessage:
- isActivating = ((EVENT.message & 0x01) != 0);
- activateEvent: if (isActivating)
- {
- // Activate this window. Activate events define theWindow from the
- // event record, while suspend/resume uses the pre-set FrontWindow value.
- SelectWindow(theWindow);
- SetPort(theWindow);
- (void) TEFromScrap();
- }
- if (IsOurWindow(theWindow))
- {
- ActivateBrowser((BrowserPtr) theWindow, isActivating);
- // Globalize the current window for the debugger's convenience.
- if (isActivating)
- gCurrentBrowserPtr = (BrowserPtr) theWindow;
- }
- else { /* Desk accessory or what? */ }
- gInForeground = isActivating;
- *sleepTimePtr = (gInForeground) ? 6 : 60;
- gUpdateMenusNeeded = TRUE;
- break;
- }
- break;
- }
- #undef EVENT
- }
-
- //--------------------------------------------------------------------------------
- // The user clicked on something. Handle application-wide processing here, or call
- // a Browser function for specific action.
- void DoMouseEvent(const EventRecord * eventRecordPtr)
- {
- WindowPtr theWindow;
- short whichPart;
- #define EVENT (*eventRecordPtr)
-
- whichPart = FindWindow(EVENT.where, &theWindow);
- if (theWindow == NULL)
- theWindow = FrontWindow();
- if (whichPart == inMenuBar && IsOurWindow(theWindow) == FALSE)
- theWindow = FrontWindow();
- switch (whichPart)
- {
- case inDesk:
- break;
-
- case inMenuBar:
- InitCursor();
- DoCommand(theWindow, MenuSelect(EVENT.where));
- break;
-
- case inDrag:
- DragWindow(theWindow, EVENT.where, &qd.screenBits.bounds);
- break;
-
- case inZoomIn:
- case inZoomOut:
- if (IsOurWindow(theWindow) && TrackBox(theWindow, EVENT.where, whichPart))
- {
- DoZoomWindow(theWindow, whichPart);
- DecorateBrowserWindow((BrowserPtr) theWindow); //goto resizeWindow;
- }
- break;
-
- case inGrow:
- if (IsOurWindow(theWindow)
- && DoGrowWindow(theWindow, EVENT.where, kMinWindowWidth, kMinWindowHeight))
- {
- DecorateBrowserWindow((BrowserPtr) theWindow);
- }
- break;
-
- case inGoAway:
- if (TrackGoAway(theWindow, EVENT.where)) {
- if (IsOurWindow(theWindow))
- {
- DisposeBrowser((BrowserPtr) theWindow);
- if (gOpenWindowCount <= 0)
- gQuitNow = TRUE;
- }
- else
- SysBeep(10);
- }
- break;
-
- case inContent:
- if (theWindow != FrontWindow())
- SelectWindow(theWindow);
- else if (IsOurWindow(theWindow)) {
- DoContentClick((BrowserPtr) theWindow, eventRecordPtr);
- }
- else { /* Nothing happens here */ }
- break;
-
- default:
- break; /* Bogus click: ignore */
- }
- #undef EVENT
- }
-
- //--------------------------------------------------------------------------------
- // Process a menu or keystroke command.
- void DoCommand(WindowPtr theWindow, long menuChoice)
- {
- short menuItem;
- Str255 menuText;
- GrafPtr savePort;
- BrowserPtr browserPtr;
- Boolean oldSortByName;
-
- menuItem = LoWord(menuChoice);
- switch (HiWord(menuChoice))
- {
- case MENU_Apple:
- if (menuItem == kAppleAbout)
- DoAbout();
- else
- {
- GetMenuItemText(gAppleMenu, menuItem, menuText);
- AdjustEditMenu(TRUE);
- GetPort(&savePort);
- OpenDeskAcc(menuText);
- SetPort(savePort);
- AdjustEditMenu(IsOurWindow(theWindow) == FALSE);
- }
- break;
-
- case MENU_File:
- switch (menuItem)
- {
- case kFileSaveAs:
- CreateOutputFile();
- break;
- case kFilePageSetup:
- DoPageSetup();
- break;
- case kFilePrint:
- if (IsOurWindow(theWindow))
- PrintBrowserWindow((BrowserPtr) theWindow);
- break;
- case kFileQuit:
- gQuitNow = TRUE;
- break;
- }
- break;
-
- case MENU_Edit:
- if (SystemEdit(menuItem - 1) == FALSE)
- SysBeep(10);
- break;
-
- case MENU_Options:
- if (IsOurWindow(theWindow))
- {
- browserPtr = (BrowserPtr) theWindow;
- oldSortByName = BROWSER.sortByName;
- switch (menuItem)
- {
- case kOptionSortByName:
- BROWSER.sortByName = TRUE;
- break;
- case kOptionSortByProperty:
- BROWSER.sortByName = FALSE;
- break;
- case kOptionRefreshDisplay:
- DoRefreshDisplay(browserPtr);
- break;
- case kOptionSetFontInfo:
- if (AEInteractionOK((AEIdleUPP) &gAEIdleUPP)
- && SetFontInfoDialog(browserPtr))
- DoSetFontInfo(browserPtr);
- break;
- }
- if (oldSortByName != BROWSER.sortByName) {
- gUpdateMenusNeeded = TRUE;
- SortAndDisplayBrowserWindow(browserPtr);
- }
- }
- break;
- }
- HiliteMenu(0);
- }
-
- //--------------------------------------------------------------------------------
- // Enable/disable menu options.
- void AdjustMenus(void)
- {
- register BrowserPtr browserPtr;
- Boolean isOurWindow;
-
- isOurWindow = IsOurWindow(FrontWindow());
- EnableItem(gAppleMenu, kAppleAbout);
- EnableItem(gFileMenu, kFileQuit);
- EnableItem(gFileMenu, kFilePageSetup);
- AdjustEditMenu(isOurWindow == FALSE);
- if (isOurWindow)
- {
- browserPtr = (BrowserPtr) FrontWindow();
- EnableItem(gOptionMenu, 0);
- EnableItem(gFileMenu, kFileSaveAs);
- EnableItem(gFileMenu, kFilePrint);
- CheckItem(gOptionMenu, kOptionSortByName, BROWSER.sortByName);
- CheckItem(gOptionMenu, kOptionSortByProperty, !BROWSER.sortByName);
- } else {
- DisableItem(gOptionMenu, 0);
- DisableItem(gFileMenu, kFileSaveAs);
- DisableItem(gFileMenu, kFilePrint);
- }
- }
-
- //--------------------------------------------------------------------------------
- // Enable/disable Edit Menu options.
- void
- AdjustEditMenu(Boolean isDeskAcc)
- {
- if (isDeskAcc) {
- EnableItem(gEditMenu, kEditUndo);
- EnableItem(gEditMenu, kEditCut);
- EnableItem(gEditMenu, kEditCopy);
- EnableItem(gEditMenu, kEditPaste);
- EnableItem(gEditMenu, kEditClear);
- }
- else {
- DisableItem(gEditMenu, kEditUndo);
- DisableItem(gEditMenu, kEditCut);
- DisableItem(gEditMenu, kEditCopy);
- DisableItem(gEditMenu, kEditPaste);
- DisableItem(gEditMenu, kEditClear);
- }
- }
-
- //--------------------------------------------------------------------------------
- // Perform the normal application initialization. This must be extended for "real"
- // applications. The only thing this module does is initialize the managers.
- void InitMacintosh(void)
- {
- int i;
-
- MaxApplZone();
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0);
- HNoPurge((Handle) GetCursor(watchCursor));
- SetCursor(*GetCursor(watchCursor));
- for (i = 0; i < 3; i++)
- EventAvail(everyEvent, &gEventRecord);
- }
-
- //--------------------------------------------------------------------------------
- // Continue initialization.
- void InitApplication(void)
- {
- (void) TEFromScrap();
- SetMenuBar(GetNewMBar(MBAR_MenuBar));
- gAppleMenu = GetMenuHandle(MENU_Apple);
- gFileMenu = GetMenuHandle(MENU_File);
- gEditMenu = GetMenuHandle(MENU_Edit);
- gOptionMenu = GetMenuHandle(MENU_Options);
- AppendResMenu(GetMenuHandle(MENU_Apple), 'DRVR');
- DrawMenuBar();
- SetupAnimatedCursor(ACUR_Animator);
- }
-
- //--------------------------------------------------------------------------------
- // Return TRUE if this is a browser window.
- Boolean IsOurWindow(WindowPtr theWindow)
- {
- if (theWindow == NULL || ((WindowPeek) theWindow)->windowKind != userKind)
- return (FALSE);
- else
- return (TRUE);
- }
-
- //--------------------------------------------------------------------------------
- void pstrcpy(StringPtr dst, ConstStr255Param src)
- {
- BlockMoveData(src, dst, src[0] + 1);
- }
-
-
- //--------------------------------------------------------------------------------
- void pstrcat(StringPtr dst, ConstStr255Param src)
- {
- short length;
-
- length = 255 - dst[0];
- if (length > src[0])
- length = src[0];
- BlockMoveData(&src[1], &dst[1] + dst[0], length);
- dst[0] += length;
- }
-
-
- //--------------------------------------------------------------------------------
- // Algorithm from New Inside Mac (Toolbox Essentials) 4-55
- void DoZoomWindow(WindowPtr theWindow, short whichPart)
- {
- GDHandle gd, gdZoom;
- GrafPtr savePort;
- Rect windowRect, zoomRect, intersection;
- long thisArea, greatestArea, response;
- short windowTitleHeight;
- Boolean hasColorQuickDraw;
- #define PEEK (*((WindowPeek) theWindow))
- #define STATE (**((WStateDataHandle) PEEK.dataHandle))
-
- GetPort(&savePort);
- SetPort(theWindow);
-
- hasColorQuickDraw = FALSE;
- if (Gestalt(gestaltQuickdrawVersion, &response) == noErr
- && response >= gestalt8BitQD)
- hasColorQuickDraw = TRUE;
- if (whichPart == inZoomOut) {
- if (hasColorQuickDraw == FALSE) {
-
- // This shouldn't happen on a modern system, but, if it does, just
- // force a single screen zoom.
- zoomRect = qd.screenBits.bounds;
- InsetRect(&zoomRect, 4, 4);
- STATE.stdState = zoomRect;
- }
- else {
- // We have color QuickDraw. Locate the screen that contains
- // the largest area of the window and zoom to that screen.
- windowRect = theWindow->portRect;
- LocalToGlobal(&topLeft(windowRect));
- LocalToGlobal(&botRight(windowRect));
- windowTitleHeight = windowRect.top - 1 - (**PEEK.strucRgn).rgnBBox.top;
- windowRect.top -= windowTitleHeight;
- greatestArea = 0;
- gdZoom = NULL;
-
- // Look at all graphics devices and find an intersection. Then
- // select the largest intersecting screen.
- for (gd = GetDeviceList(); gd != NULL; gd = GetNextDevice(gd)) {
- if (TestDeviceAttribute(gd, screenDevice)
- && TestDeviceAttribute(gd, screenActive)
- && SectRect(&windowRect, &(**gd).gdRect, &intersection)) {
- thisArea = ((long) width(intersection)) * ((long) height(intersection));
- if (thisArea > greatestArea) {
- greatestArea = thisArea;
- gdZoom = gd;
- }
- }
- }
- // If we're zooming to the device with the menu bar,
- // allow for its height.
- if (GetMainDevice() == gdZoom)
- windowTitleHeight += GetMBarHeight();
- zoomRect = (**gdZoom).gdRect;
- InsetRect(&zoomRect, 3, 3);
- zoomRect.top += windowTitleHeight;
- STATE.stdState = zoomRect;
- } /* End if color QuickDraw */
- } /* End if zoom out */
- ZoomWindow(theWindow, whichPart, (theWindow == FrontWindow()));
-
- // Zoom redraws the entire window.
- EraseRect(&theWindow->portRect);
- InvalRect(&theWindow->portRect);
- SetPort(savePort);
- #undef PEEK
- #undef STATE
- }
-
- //--------------------------------------------------------------------------------
- // Algorithm from New Inside Mac (Toolbox Essentials) 4-58 (simplified)
- // We assume that the window can cover the entire screen.
- Boolean DoGrowWindow(WindowPtr theWindow, Point startingPoint, short minimumWidth, short minimumHeight)
- {
- long growSize;
- Rect limitRect;
-
- limitRect.left = minimumWidth;
- limitRect.top = minimumHeight;
- limitRect.right = qd.screenBits.bounds.right;
- limitRect.bottom = qd.screenBits.bounds.bottom;
- growSize = GrowWindow(theWindow, startingPoint, &limitRect);
- if (growSize != 0) {
- SizeWindow(theWindow, LoWord(growSize), HiWord(growSize), TRUE);
-
- // Force a redraw of the entire window, (The correct algorithm
- // excludes the intersection of the old view rect and the new view
- // rect, but this doesn't work correctly yet.) Invalidate any prior
- // update region in any case.
- EraseRect(&theWindow->portRect);
- InvalRect(&theWindow->portRect);
- }
- return (growSize != 0);
- }
-
- //--------------------------------------------------------------------------------
- void
- DoPageSetup(void)
- {
- OSErr status;
-
- PrOpen();
- status = PrError();
- if (status != noErr)
- NonFatalError(status, "\pPrinting disabled");
- else {
- if (gPrintHandle == NULL) {
- gPrintHandle = (THPrint) NewHandle(sizeof (TPrint));
- if (gPrintHandle != NULL)
- PrintDefault(gPrintHandle);
- }
- if (gPrintHandle != NULL)
- (void) PrStlDialog(gPrintHandle);
- PrClose();
- }
- }
-
- //--------------------------------------------------------------------------------
- void DoAbout(void)
- {
- GrafPtr savePort;
- DialogPtr dialog;
- short dialogItem;
-
- dialog = GetNewDialog(DLOG_About, NULL, (WindowPtr) -1L);
- if (dialog != NULL) {
- GetPort(&savePort);
- SetPort(dialog);
- ShowWindow(dialog);
- ModalDialog(NULL, &dialogItem);
- DisposeDialog(dialog);
- SetPort(savePort);
- }
- }
-
- //--------------------------------------------------------------------------------
- void
- CheckError( OSErr errorStatus, ConstStr255Param errorMsg)
- {
- if (errorStatus != noErr && errorStatus != userCanceledErr)
- NonFatalError(errorStatus, errorMsg);
- }
-
- //--------------------------------------------------------------------------------
- void NonFatalError( OSErr errorStatus, ConstStr255Param errorMsg)
- {
- if (ErrorMessage(ALRT_NonFatalError, errorStatus, errorMsg) == kOKButton)
- gQuitNow = TRUE;
- }
-
- //--------------------------------------------------------------------------------
- void FatalError( OSErr errorStatus, ConstStr255Param errorMsg)
- {
- ErrorMessage(ALRT_FatalError, errorStatus, errorMsg);
- ExitToShell();
- }
-
-
- //--------------------------------------------------------------------------------
- short ErrorMessage(
- short alertID,
- OSErr errorStatus,
- ConstStr255Param errorMsg)
- {
- Handle errorTextHdl;
- StringPtr errorTextPtr;
- Str15 errorStatusText;
- short result;
-
- if (AEInteractionOK((AEIdleUPP) &gAEIdleUPP) == FALSE)
- result = kCancelButton;
- else {
- NumToString(errorStatus, errorStatusText);
- errorTextHdl = GetResource('Estr', errorStatus);
- if (errorTextHdl != NULL) {
- HLock(errorTextHdl);
- errorTextPtr = (StringPtr) errorTextHdl;
- }
- else {
- errorTextPtr = "\pSystem Error";
- }
- ParamText(errorStatusText, errorTextPtr, errorMsg, "\p");
- InitCursor();
- result = StopAlert(alertID, NULL);
- if (errorTextHdl != NULL)
- ReleaseResource(errorTextHdl);
- }
- return (result);
- }
-
-
- //--------------------------------------------------------------------------------
- pascal Boolean MyAEIdleProc(
- const EventRecord *theEventPtr,
- long *sleepTime,
- RgnHandle *mouseRgn)
- {
- UNUSED(mouseRgn);
- if (theEventPtr->what == kHighLevelEvent)
- return (TRUE);
- else {
- ProcessThisEvent(theEventPtr, sleepTime); /* Application specific */
- return (FALSE);
- }
- }
-